package com.neusoft.elmboot.controller;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：ljz
 * @Date：2022/11/21 15:54
 * @Description:
 */

import com.neusoft.elmboot.po.Credit;
import com.neusoft.elmboot.service.CreditService;

@RestController
@RequestMapping("/Credit")
public class CreditController {
	@Autowired
	private CreditService creditService;

	// 查询可用总数
	@GetMapping("/totalNum")
	public Integer getTotalCreditByUserId(Credit credit) throws Exception {
		return creditService.getTotalCreditByUserId(credit.getUserId());
	}

	// 明细流水
	@GetMapping("/availableCredit")
	public List<Credit> getAvailableCreditByUserId(Credit credit) throws Exception {
		return creditService.listAvailableCreditByUserId(credit.getUserId());
	}

	// 明细流水
	@GetMapping("/userId")
	public List<Credit> getCreditByUserId(Credit credit) throws Exception {
		return creditService.listAllCreditByUserId(credit.getUserId());
	}

	// 明细流水
	@GetMapping("/channelType")
	public List<Credit> getCreditByUserIdAndChannelType(Credit credit) throws Exception {
		return creditService.listCreditByUserIdAndChannelType(credit.getUserId(), credit.getChannelType());
	}

	// 积分赚取
	@PostMapping("/userId")
	public int insertCredit(Credit credit) throws Exception {
		return creditService.insertCredit(credit,BigDecimal.ZERO);
	}
	
	@PutMapping("/userId")
	public int useCredit(Credit credit, double count) {
		BigDecimal count1 = new BigDecimal(count);
		return creditService.useCredit(credit,count1);
	}
}
